use "C:\Users\ibo6\OneDrive - The Pennsylvania State University\Working Papers\Target Hardening\v10 Terrorism and Political Violence\R & R\Analysis\rdyads2.dta", replace


* Selection criteria 
generate s = total > 0 



* TABLE 2
** Model 1: Soft Targets (simple)
heckman softtot str_intel_log_l a_l suictot_l, ///
select(s = str_intel_log_l a_l pop_log) vce(cluster dyadid)

estimates store t1_soft_simple

** Model 2: Soft Targets (extended)
heckman softtot str_intel_log_l a_l suictot_l coin_deaths_log_l inten epr ib2.ideology, select(s = str_intel_log_l a_l coin_deaths_log_l pop_log) vce(cluster dyadid)

estimates store t1_soft_extended

** Model 3: Civilian Targets Only (extended)
heckman civitot str_intel_log_l a_l suictot_l coin_deaths_log_l inten epr ib2.ideology, select(s = str_intel_log_l a_l coin_deaths_log_l pop_log) vce(cluster dyadid)

estimates store t1_civi_extended

** Model 4: Hard Targets (extended)
heckman hardtot str_intel_log_l a_l suictot_l coin_deaths_log_l inten epr ib2.ideology, select(s = str_intel_log_l a_l coin_deaths_log_l pop_log) vce(cluster dyadid)

estimates store t1_hard_extended

** Model 5: Mlitary Targets Only (extended)
heckman militot str_intel_log_l a_l suictot_l coin_deaths_log_l inten epr ib2.ideology, select(s = str_intel_log_l a_l coin_deaths_log_l pop_log) vce(cluster dyadid)
estimates store t1_mili_extended




ssc install estout
label variable str_intel_log_l "Hardening (lagged)"
label variable a_l "Success rate against hard targets (lagged)"
label variable suictot_l "Ratio of suicide attacks (lagged)"
label variable coin_deaths_log_l "COIN casualties (lagged)"
label variable inten "Conflict intensity"
label variable epr "Ethnic fractionalization"
label variable ideology "Group ideology"
label variable mao "Maoist insurgency"
label variable kashmir "Kashmir insurgency"
label variable north "Northeast insurgency"
label variable gdp_per_log "Logged GDP per capita"


label define ideology 1 "Ethnonationalist" 2 "Religious" 3 "Leftist" 4 "Other"
label values ideology ideology


esttab t1_soft_simple t1_soft_extended t1_civi_extended t1_hard_extended t1_mili_extended using table2.csv, b(%5.3f) mlabel("Soft" "Soft" "Civilian" "Hard" "Military") se starlevels(* 0.1 ** 0.05 *** 0.01) label noconstant nobaselevels title("Heckman Selection Models of Target Selection in Relevant State-Group Dyads in India, 2004-2016") addnotes("Heckman Selection Models are estimated using full maximum likelihood with Stata's heckman command. The bottom half of the table presents estimations of the selection equation. The selection criteria is whether or not a given relevant state-group dyad experienced at least 1 insurgent attack in a given year. The upper half of the table presents estimations of prevalence of attacks against respective target types. The dependent variables are the ratio of number of attacks against respective target types to total number of attacks committed in a given relevant state-group dyad in a given year. State population is logged. Robust standard errors clustered on relevant state-group dyads are presented in parantheses.")






* FIGURE 5: Predictions
** Panel A
estimates restore t1_soft_extended
margins, at(str_intel_log_l=(2(0.5)8)) noatlegend
marginsplot, recast(line) recastci(rline) plot1opts(lcolor(black)) ciopt(lpattern(dash) color(black)) yline(0) title("Panel A: Selection of soft targets ") ytitle("Predicted ratio")  ylabel(0(0.2)1) xlabel(2(2)8) name(t1panelA, replace)
graph save "t1panelA"
** Panel B
estimates restore t1_civi_extended
margins, at(str_intel_log_l=(2(0.5)8)) noatlegend
marginsplot, recast(line) recastci(rline) plot1opts(lcolor(black)) ciopt(lpattern(dash) color(black)) yline(0) title("Panel B: Selection of civilian targets ") ytitle("Predicted ratio")  ylabel(0(0.2)1) xlabel(2(2)8) name(t1panelB, replace)
graph save "t1panelB"
** Panel C
estimates restore t1_hard_extended
margins, at(str_intel_log_l=(2(0.5)8)) noatlegend
marginsplot, recast(line) recastci(rline) plot1opts(lcolor(black)) ciopt(lpattern(dash) color(black)) yline(0) title("Panel C: Selection of hard targets ") ytitle("Predicted ratio")  ylabel(0(0.2)1) xlabel(2(2)8) name(t1panelC, replace)
graph save "t1panelC" 
** Panel D
estimates restore t1_mili_extended
margins, at(str_intel_log_l=(2(0.5)8)) noatlegend
marginsplot, recast(line) recastci(rline) plot1opts(lcolor(black)) ciopt(lpattern(dash) color(black)) yline(0) title("Panel D: Selection of military targets ") ytitle("Predicted ratio")  ylabel(0(0.2)1) xlabel(2(2)8) name(t1panelD, replace)
graph save "t1panelD" 
graph combine "t1panelA" "t1panelB" "t1panelC" "t1panelD"




* TABLE 3
** Model 6: Interaction of hardening and ideology
heckman softtot c.str_intel_log_l##ib2.ideology a_l suictot_l coin_deaths_log_l inten epr, ///
select(s = str_intel_log_l a_l coin_deaths_log_l pop_log) vce(cluster dyadid)

estimates store t2_hardening_ideology

** Model 7: Interaction of success rate against hard targets and ideology
heckman softtot str_intel_log_l c.a_l##ib2.ideology suictot_l coin_deaths_log_l inten epr, ///
select(s = str_intel_log_l a_l coin_deaths_log_l pop_log) vce(cluster dyadid)

estimates store t2_success_ideology





esttab t2_hardening_ideology t2_success_ideology using table3.csv, b(%5.3f) mlabel("Soft" "Soft" "Soft" "Soft") se starlevels(* 0.1 ** 0.05 *** 0.01) label noconstant nobaselevels title("Heckman Selection Models of Target Selection in Relevant State-Group Dyads in India, 2004-2016") addnotes("The dependent variables are the ratio of the number of attacks against respective target types to the total number of attacks committed in a given relevant state-group dyad in a given year. Hardening, Success rate against hard targets, the ratio of suicide attacks, and COIN casualties are lagged one year. State population is logged. The reference category for the group ideology is religious-fundamentalist groups. The constituent terms of all interactions and control variables are included in the models but not reported here to save space. Full model specifications are in the Appendix.")







* FIGURE 6:  Interaction of hardening and ideology
** Panel A-B-C-D
estimates restore t2_hardening_ideology
margins ideology, at(str_intel_log_l=(2(0.1)8)) atmeans
marginsplot, by (ideology) recast(line) recastci(rline) plot1opts(lcolor(black)) ciopt(lpattern(dash) color(black)) yline(0) byopts(title("Hardening, group ideology and selection of soft targets")) name(t2panelABCD, replace)
graph save "t2panelABCD"

